package com.qf.java2201.dao.impl;

import com.qf.java2201.dao.TypeDao;
import com.qf.java2201.pojo.HType;
import com.qf.java2201.utils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @date 2022/4/7
 * @desc
 */
public class TypeDaoImpl implements TypeDao {

    QueryRunner queryRunner = new QueryRunner(DbUtils.getDs());
    @Override
    public List<HType> findAllTypes() {
        String sql = "select * from h_type";
        List<HType> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HType.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return query;
    }

    @Override
    public List<HType> findListByTgroup(int tgroup) {
        String sql = "select * from h_type where tgroup = ? ";
        List<HType> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HType.class), tgroup);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return query;
    }
}
